// 测试所有鼓励师的自动降级功能
const mentors = ['sheldon', 'confucius', 'guo'];

async function testMentor(mentorId) {
  try {
    console.log(`\n🧪 测试鼓励师: ${mentorId}`);

    const response = await fetch('http://localhost:3001/api/encourage', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        mentorId: mentorId,
        userInput: `我是${mentorId}，遇到了编程困难，需要鼓励！`
      }),
    });

    if (!response.ok) {
      console.error(`❌ ${mentorId} 测试失败: HTTP ${response.status}`);
      return;
    }

    const data = await response.json();

    console.log(`✅ ${mentorId} 测试成功:`);
    console.log(`   - 回复: ${data.reply.substring(0, 50)}...`);
    console.log(`   - 鼓励师: ${data.mentor}`);
    console.log(`   - 是否降级: ${data.isFallbackAPI ? '是' : '否'}`);
    if (data.fallbackReason) {
      console.log(`   - 降级原因: ${data.fallbackReason}`);
    }

  } catch (error) {
    console.error(`❌ ${mentorId} 测试出错:`, error.message);
  }
}

async function runAllTests() {
  console.log('🚀 开始测试所有鼓励师的自动降级功能...\n');

  for (const mentor of mentors) {
    await testMentor(mentor);
    // 等待一下避免请求过快
    await new Promise(resolve => setTimeout(resolve, 500));
  }

  console.log('\n🎉 所有测试完成！');
}

runAllTests();